package com.example.project.webControlleer;

import com.example.project.dao.CarDAO;
import com.example.project.pojo.Car;
import com.example.project.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;

@Controller
@RequestMapping("web")
public class WebAddCarController {

    @RequestMapping("addcar")
    public String addcar() {
        return "web/addcar";
    }

    @RequestMapping("addCarName")
    @ResponseBody
    public String addCarName(Car car,  HttpServletRequest request) {
        try {
            request.setCharacterEncoding("utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        CarDAO carDAO = new CarDAO();

        String carLicense = car.getLicense();
        User user =(User)request.getSession().getAttribute("user");
        carDAO.addCar(carLicense, user.getId());


        return "";
    }
}
